package adv9;

import java.net.*;
import java.util.*;
import java.io.*;

public class ObjectFileThread extends Thread {
	private Socket socket;

	public ObjectFileThread(Socket s) {
		this.socket = s;
	}

	@Override
	public void run() {
		System.out.println(socket + "连接了");
		Map<String, byte[]> m = new HashMap<String, byte[]>();
		String folder = "C:/Users/Administrator/Desktop/56";
		try {
			File f = new File(folder);
			File fs[] = f.listFiles();
			for (File t : fs) {

				if (t.getName().endsWith("txt")) {
					FileInputStream fin = new FileInputStream(t);
					byte b[] = new byte[fin.available()];
					fin.read(b);
					m.put(t.getName(), b);
					fin.close();
				}
			}
			// InputStream in = socket.getInputStream();
			OutputStream out = socket.getOutputStream();
			ObjectOutputStream oout = new ObjectOutputStream(out);
			// ObjectInputStream oin = new ObjectInputStream(in);
			oout.writeObject(m);
			oout.flush();// 手动刷新

			System.out.println("send ok-> " + socket.getInetAddress() + ":");
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			// e.printStackTrace();
		} finally {
			if (socket != null)
				try {
					socket.close();
				} catch (IOException e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
		}

	}
}
